package ltd.bugs.cute.api.http;

import java.util.HashMap;
import java.util.Map;

import ltd.bugs.cute.api.http.statuscode.CommonStatusCode;

/**
 * 基于json的http响应结果.响应结果包含code、message等信息
 * 
 * @author zhengzhq
 *
 */
public class RestResponse extends HashMap<String, Object> {

  private static final long serialVersionUID = 2949621061336216844L;

  public static RestResponse SUCCESS = new RestResponse(CommonStatusCode.SUCCESS);

  public RestResponse(CommonStatusCode statusCode) {
    this(statusCode.code(), statusCode.message());
  }

  public RestResponse(int code, String message) {
    this.put("code", code);
    this.put("message", message);
  }

  /**
   * 设置需要成功响应的数据
   * 
   * @param dataMap
   */
  public RestResponse(Map<String, Object> dataMap) {
    // 设置data的肯定是响应成功的
    this(CommonStatusCode.SUCCESS);
    putAll(dataMap);
  }
}
